<template>
  <div class="app-container">
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="指标编码" prop="findxTpCode">
          <el-input disabled="true"
                    v-model="queryParams.findxTpCode"
                    clearable
          />
        </el-form-item>
        <el-form-item label="指标名称" prop="findxNm">
          <el-input disabled="true"
                    v-model="queryParams.findxNm"
                    clearable
          />
        </el-form-item>
      </el-form>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="指标说明" prop="remark">
          <el-input style="width: 500px;" disabled="true"
                    v-model="queryParams.remark"
                    clearable
          />
        </el-form-item>
      </el-form>
    </div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['reportworld:hswd:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['reportworld:hswd:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['reportworld:hswd:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['reportworld:hswd:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="handleClose"
        >关闭</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border="border" max-height="550px" v-loading="loading" :data="dimZbWdVoList"
              @selection-change="handleSelectionChange" @row-click="rowClick"
              @sort-change="handleSortChange" :row-style="tableRowStyle" ref="zbwdInfo">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column
        v-hasPermi="['reportworld:hswd:query']"
        label="操作" align="center" width="100" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row,false)"
            v-hasPermi="['reportworld:hswd:query']"
          >详情
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="核算维度" align="center" style="font-size: 20px; font-weight: bold;">
        <el-table-column label="证券品种" align="center" prop="hsZqpz" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.hsZqpz,'A00268')}}
          </template>
        </el-table-column>
        <el-table-column label="证券明细品种" align="center" prop="hsZqmxpz" width="200px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.hsZqmxpz,'A00269')}}
          </template>
        </el-table-column>
        <el-table-column label="市场代码" align="center" width="150px" prop="hsScdm" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.hsScdm,'A00270')}}
          </template>
        </el-table-column>
        <el-table-column label="币种" align="center" prop="bz" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.bz,'A00060')}}
          </template>
        </el-table-column>
        <el-table-column label="资产类型" align="center" prop="zclx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zclx,'A00260')}}
          </template>
        </el-table-column>
        <el-table-column label="投资分类" align="center" prop="tzfl" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.tzfl,'A00263')}}
          </template>
        </el-table-column>
        <el-table-column label="核算项目" align="center" prop="hsxm" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.hsxm,'A00264')}}
          </template>
        </el-table-column>
        <el-table-column label="账户或费用代码" align="center" prop="zhfydm" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zhfydm,'A00281')}}
          </template>
        </el-table-column>
        <el-table-column label="发行方式" align="center" prop="fxfs" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.fxfs,'A00262')}}
          </template>
        </el-table-column>
        <el-table-column label="交易属性" align="center" prop="jysx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.jysx,'A00261')}}
          </template>
        </el-table-column>
      </el-table-column>

      <el-table-column label="资讯维度" align="center">
        <el-table-column label="证券分类" align="center" prop="zqfl" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zqfl,'ZQ0003')}}
          </template>
        </el-table-column>
        <el-table-column label="证券类别" align="center" prop="zqlb" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zqlb,'ZQ0004')}}
          </template>
        </el-table-column>
        <el-table-column label="上市市场" align="center" prop="zxSssc" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zxSssc,'A00270')}}
          </template>
        </el-table-column>
        <el-table-column label="证券类型" align="center" prop="zqlx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zqlx,'ZQ0001')}}
          </template>
        </el-table-column>
        <el-table-column label="证券类型小类" align="center" prop="zqlxxl" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zqlxxl,'A00400')}}
          </template>
        </el-table-column>
        <el-table-column label="行业分类" align="center" prop="hyfl" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.hyfl,'HY0001')}}
          </template>
        </el-table-column>
        <el-table-column label="公司代码" align="center" prop="gsdm" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="统一社会信用代码" align="center" prop="tyshxydm" width="180px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="债项评级" align="center" prop="zxPjnr" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="主体评级" align="center" prop="ztPjnr" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="债项评级机构" align="center" prop="zxPjjg" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="主体评级机构" align="center" prop="ztPjjg" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="发行人名称" align="center" prop="fxrmc" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="是否永续债" align="center" prop="sfyxz" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="评级信息" align="center" prop="zxZtyxpj" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
      </el-table-column>

      <el-table-column label="交易维度" align="center">
        <el-table-column label="交易属性" align="center" prop="jysx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.jysx,'A00261')}}
          </template>
        </el-table-column>
        <el-table-column label="交易类型" align="center" prop="jylx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.jylx,'A00274')}}
          </template>
        </el-table-column>
        <el-table-column label="交易方式" align="center" prop="jyfs" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.jyfs,'A00272')}}
          </template>
        </el-table-column>
        <el-table-column label="业务类型" align="center" prop="ywlx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.ywlx,'A00271')}}
          </template>
        </el-table-column>
        <el-table-column label="证券品种" align="center" prop="zqpz" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zqpz,'A00268')}}
          </template>
        </el-table-column>
        <el-table-column label="证券品种明细" align="center" prop="zqmxpz" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.zqmxpz,'A00269')}}
          </template>
        </el-table-column>
        <el-table-column label="财务市场" align="center" prop="cwsc" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.cwsc,'A00270')}}
          </template>
        </el-table-column>
        <el-table-column label="投资分类" align="center" prop="tzfl" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.tzfl,'A00263')}}
          </template>
        </el-table-column>
        <el-table-column label="计息基础" align="center" prop="jxjc" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.jxjc,'LC00033')}}
          </template>
        </el-table-column>
        <el-table-column label="互换类型" align="center" prop="hhlx" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']">
          <template slot-scope="scope">
            {{getTpGlExhibDatadicts(scope.row.hhlx,'C2G107')}}
          </template>
        </el-table-column>
        <el-table-column label="对手方代码" align="center" prop="dsfdm" width="150px" :show-overflow-tooltip="true"
                         sortable="custom" :sort-orders="['descending', 'ascending']"/>
      </el-table-column>
      <el-table-column label="非标维度" align="center">
        <el-table-column label="人行分类" align="center" prop="fbRhfl" width="150px" :show-overflow-tooltip="true" sortable="custom"
                         :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="行业分类" align="center" prop="fbHyfl" width="150px" :show-overflow-tooltip="true" sortable="custom"
                         :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="企业规模" align="center" prop="fbQygm" width="150px" :show-overflow-tooltip="true" sortable="custom"
                         :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="地区" align="center" prop="fbDq"  width="150px":show-overflow-tooltip="true" sortable="custom"
                         :sort-orders="['descending', 'ascending']"/>
        <el-table-column label="基础资产类型" align="center" prop="fbJczclx" width="150px" :show-overflow-tooltip="true" sortable="custom"
                         :sort-orders="['descending', 'ascending']"/>
      </el-table-column>
    </el-table>
    <!-- 添加或修改指标类型对话框 -->
    <el-dialog  :title="title" :close-on-click-modal ="false" :visible.sync="open" width="1200px" append-to-body>
      <el-card>
        <el-tabs v-model="activeName">
          <el-tab-pane label="核算维度" name="hswd">
            <hswd-form ref="hswd" :info="info" :tpGlExhibDatadicts="tpGlExhibDatadicts"/>
          </el-tab-pane>
          <el-tab-pane label="资讯维度" name="zxwd">
            <zxwd-form ref="zxwd" :info="info" :tpGlExhibDatadicts="tpGlExhibDatadicts"/>
          </el-tab-pane>
          <el-tab-pane label="交易维度" name="jywd">
            <jywd-form ref="jywd" :info="info" :tpGlExhibDatadicts="tpGlExhibDatadicts"/>
          </el-tab-pane>
          <el-tab-pane label="非标维度" name="fbwd">
            <fbwd-form ref="fbwd" :info="info" :tpGlExhibDatadicts="tpGlExhibDatadicts"/>
          </el-tab-pane>
          <el-tab-pane label="特殊维度" name="tswd">
            <tswd-form ref="tswd" :info="info" :tpGlExhibDatadicts="tpGlExhibDatadicts"/>
          </el-tab-pane>
        </el-tabs>
        <el-form label-width="100px">
          <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
            <el-button type="primary" @click="submitForm()">提交</el-button>
            <el-button @click="open = false">返回</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </el-dialog>


  </div>
</template>

<script>
  //import { getList,init,saveZbWdInfo} from "@/api/reportworld/zbwd";
  import { getDimZblxByCode} from "@/api/reportworld/dimZblx";
  import { getTableRowStyle } from "@/utils/yss";
  import hswdForm from "./hswd";
  import zxwdForm from "./zxwd";
  import jywdForm from "./jywd";
  import fbwdForm from "./fbwd";
  import tswdForm from "./tswd";

  export default {
    name: "indexInfo",
    components: {
      jywdForm,
      zxwdForm,
      tswdForm,
      hswdForm,
      fbwdForm
    },
    data() {
      return {
        butloading:false,
        isUpdate: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 核算维度表格数据
        dimZbWdVoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        tpGlExhibDatadicts:[],
        tpGlExhibDatadictMap:{},
        // 选中选项卡的 name
        activeName: "hswd",
        // 表格的高度
        tableHeight: document.documentElement.scrollHeight - 245 + "px",
        info:{},
        // 查询参数
        queryParams: {},
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      const findxTpCode = this.$route.query && this.$route.query.findxTpCode;
      this.queryParams.findxTpCode = findxTpCode;
      const hisVersion = this.$route.query && this.$route.query.hisVersion;
      this.queryParams.hisVersion = hisVersion;
      const object = Object.assign({});
      object.findxTpCode=  this.queryParams.findxTpCode;
      object.hisVersion= this.queryParams.hisVersion;
      getDimZblxByCode(JSON.stringify(object)).then(response => {
        this.queryParams.findxNm = response.data.findxNm;
        this.queryParams.remark = response.data.remark;
     });
      this.getList();
      this.init();
    },
    methods: {
      /** 查询核算维度列表 */
      getList() {
        this.loading = false;
      /*  this.loading = true;
        getList(this.queryParams).then(response => {
          this.dimZbWdVoList = response.data;
          this.loading = false;
      });*/
      },
      init(){
       /* init(this.queryParams).then(response => {
          this.tpGlExhibDatadicts = response.tpGlExhibDatadicts;
          this.tpGlExhibDatadictMap= response.tpGlExhibDatadictMap;
      });*/
      },
      getTpGlExhibDatadicts(value,classId){
        return this.tpGlExhibDatadictMap[classId + value];
      },
      /** 返回按钮操作 */
      handleClose() {
        const obj = { path: "/reportworld/arrInfo/zblx" };
        this.$tab.closeOpenPage(obj);
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 排序触发事件 */
      handleSortChange(column, prop, order) {
        this.queryParams.orderByColumn = column.prop;
        this.queryParams.isAsc = column.order;
        this.getList();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.open = true;
        this.title="指标维度信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row,isUpdate) {
        this.reset();
        const id = row.id || this.ids
        this.open = true;
        this.title="指标维度信息";
      },
      /** 提交按钮 */
      submitForm() {
        const hswdForm = this.$refs.hswd.$refs.hswdForm;
        const zxwdForm = this.$refs.zxwd.$refs.zxwdForm;
        const jywdForm = this.$refs.jywd.$refs.jywdForm;
        const fbwdForm = this.$refs.fbwd.$refs.fbwdForm;
        const tswdForm = this.$refs.tswd.$refs.tswdForm;
        Promise.all([hswdForm, zxwdForm,jywdForm,fbwdForm,tswdForm]).then(res => {
          const validateResult = res.every(item => !!item);
        if (validateResult) {
          this.butloading=true;
          const zbWdInfo = Object.assign({}, hswdForm.model, zxwdForm.model,jywdForm.model,fbwdForm.model,tswdForm.model);
          zbWdInfo.findxTpCode = this.queryParams.findxTpCode;
          saveZbWdInfo(zbWdInfo).then(res => {
            this.$modal.msgSuccess(res.msg);
          if (res.code === 200) {
             this.open = false;
          }
        }).finally(() => {this.butloading=false});
        } else {
          this.$modal.msgError("表单校验未通过，请重新检查提交内容");
        }
      });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除数据项？').then(function() {
          return delHswd(ids);
        }).then(() => {
          this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('reportworld/hswd/export', {
          ...this.queryParams
      }, `hswd_${new Date().getTime()}.xlsx`)
      },
      tableRowStyle({ row, rowIndex}){
        return getTableRowStyle(row,rowIndex,this.ids);
      },
      /** 单击选中行数据 */
      rowClick(row) {
        this.$refs.hswd.toggleRowSelection(row);
      }
    }
  };
</script>
